<template>
  <view class="page-order-index">
    <van-sticky>
			<van-tabs :active="tabs.active" @change="changeTab" color="#3678FD">
				<van-tab v-for="(item,index) in tabs.list" :key="index" :title="item.name"></van-tab>
			</van-tabs>
		</van-sticky>
		<van-empty description="暂无数据" v-if="tabs.list[tabs.active].data.length == 0" />
    <view class="order-list" v-else>
      <view class="fly-panel" v-for="(item,index) in tabs.list[ tabs.active ].data" :key="index">
        <view class="hd">
          <text class="title">运单号：000</text>
          <text :class="'value order-status-'+ item.orderStatus">状态</text>
        </view>
        <view class="bd">
          <view class="bd-ul">
            <fly-info label="运单金额：" value="￥100" />
            <fly-info label="计划发货时间：" value="xxxx" />
            <fly-info label="发货地：" value="xxxx" />
            <fly-info label="收货地：" value="xxxx" />
          </view>
        </view>
        <view class="ft">
          <view class="flex-block">
            <view class="c-grey">2024-01-01</view>
						<view>
							<van-button round type="info" plain size="small" @tap.stop.prevent="$utils.gotoPage('/packageB/service/submit', item)" v-if="item.payState== 0">去支付</van-button>
							<van-button round type="info" plain size="small" @tap.stop.prevent="$utils.gotoPage('/packageB/order/detail', item)" class="m-l-15">查看详情</van-button>
						</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import flyInfo from '@/components/flyInfo';
export default {
  data(){
    return{
      userInfo: {},
			searchForm:{
				page: 1,
				size: 20,
				type: 1,
				orderStatus: 0,
				uid: null,
			},
			tabs:{
				active: 0,
				list: [
					{id: '0,1,2', name: '全部', data: [{id:1}], page: 0, size: 20, total: 0},
					{id: '0,1', name: '待装车', data: [], page: 0, size: 20, total: 0},
					{id: 2, name: '待卸车', data: [], page: 0, size: 20, total: 0},
					{id: 2, name: '待验收', data: [], page: 0, size: 20, total: 0},
					{id: 2, name: '已完成', data: [], page: 0, size: 20, total: 0},
				]
			},
      initData:{
				orderStatus:[],
				consultType:[],
			},
    }
  },
  components:{
    flyInfo
  },
  onLoad(){
    
  },
  onShow(){
		// if(this.$utils.checkLogin()){
    // 	this.getInitData();
		// }
  },
	onPullDownRefresh() {
		this.getList('refresh');
		setTimeout(function () {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onReachBottom(){
		this.getList();
	},
  methods:{
    async getInitData(){
      let orderStatus = await this.$http('get', '/nursing/oms/aid/itemtrees/lvto_order_status', {});
      this.initData.orderStatus = this.$utils.transformArray(orderStatus, 'itemId', 'itemName');
      let consultType = await this.$http('get', '/nursing/oms/aid/itemtrees/lvto_consult_type', {});
      this.initData.consultType = this.$utils.transformArray(consultType, 'itemId', 'itemName');
      this.getList('refresh');
    },
    getList(type){
			let index = this.tabs.active;
			let list =  this.tabs.list[index];
			this.searchForm.orderStatus = list.id;
			if(type == 'refresh'){  
				list.page = 1;
				this.searchForm.page = 1;
				list.data = [];
			}else{
				if(list.count > list.data.length){
					list.page++;
					this.searchForm.page = list.page;          
				}else{
					uni.showToast({title:'没有更多了',icon: 'none'});
					return;
				}
			}
			let param = this.$utils.getParam(this.searchForm);
			this.$http('get', '/lvto/lvtoReferralBill/getUserBillPage', param ,(data,msg) => {
				list.data = list.data.concat(data.records);
				list.total = data.total;
				this.$forceUpdate();
			});
		},
    getStatusName(id){
			let obj = this.initData.orderStatus.find(item => item.id == id);
			return obj.name;
		},
		getServiceName(id){
			let obj = this.initData.consultType.find(item => item.id == Number(id));
			console.log(obj);
			return obj.name;
		},
		changeTab(e){
			let index = e.detail.index;
			this.tabs.active = index;
			if(this.tabs.list[index].data.length == 0){
				this.getList('refresh');
			}
		}
    
  }
}
</script>